# -*- coding: UTF-8 -*-
# @Time : 2022/1/15 0015 13:24
# @Author : lyw RSW
# @Remark : 机柜

from mxsoftpy import View

from server.common.CRM.server_cabinet import CabinetServer
from utils.public.params_method import check_params


class CabinetList(View):
    """展示机柜"""

    def post(self):
        check_params(self.request.POST, ['sroom_parent'])
        return CabinetServer().list(**self.request.POST)


class CabinetAdd(View):
    """添加机柜"""

    def post(self):
        check_params(self.request.POST, ['cabinet_name', 'total_space', 'sroom_parent'])
        return CabinetServer().add(**self.request.POST)


class CabinetRetrieve(View):
    """回显机柜"""

    def post(self):
        check_params(self.request.POST, ['cabinet_code'])
        return CabinetServer().retrieve(**self.request.POST)


class CabinetSelect(View):
    """添加已有的机柜"""

    def post(self):
        check_params(self.request.POST, ['code_list', 'sroom_parent'])
        return CabinetServer().select(**self.request.POST)


class CabinetUpdate(View):
    """更新机柜"""

    def post(self):
        check_params(self.request.POST, ['cabinet_code'])
        return CabinetServer().update(**self.request.POST)


class CabinetUnbound(View):
    """移除机柜"""

    def post(self):
        check_params(self.request.POST, ['code_list'])
        return CabinetServer().unbound(**self.request.POST)


class CabinetDelete(View):
    """删除机柜"""

    def post(self):
        check_params(self.request.POST, ['code_list'])
        return CabinetServer().delete(**self.request.POST)


class CabinetAdds(View):
    """机柜管理新建机柜"""

    def post(self):
        check_params(self.request.POST, ['cabinet_name', 'total_space'])
        return CabinetServer().add(**self.request.POST)


class CabinetDistribution(View):
    """机柜管理绑定机房"""

    def post(self):
        check_params(self.request.POST, ['cabinet_code', 'sroom_type', 'sroom_parent'])
        if not self.request.POST['sroom_type'].isdigit() or int(self.request.POST['sroom_type']) != 2:
            return '您选择的不是机房'
        return CabinetServer().Distribution(**self.request.POST)
